//
//  Popover.m
//  Baidu
//
//  Created by C_HAO on 15/4/2.
//  Copyright (c) 2015年 C_HAO. All rights reserved.
//

#import "Popover.h"

@implementation Popover

@synthesize popover;

- (id)init {
    if (self = [super init]) {
        viewController = [[ShowViewController alloc] initWithNibName:@"ShowViewController" bundle:[NSBundle mainBundle]];
        [popoverWindow.contentView addSubview:viewController.view];
    }
    return self;
}


- (void)showPopover:(id)sender
{
    if (popover == nil) {
        popover = [NSPopover new];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10
        popover.appearance = [NSAppearance appearanceNamed:@"NSAppearanceNameVibrantLight"];
#else
        
#endif
        popover.delegate = self;
        popover.contentViewController = viewController;
        popover.behavior = NSPopoverBehaviorTransient;
    }
    CGRect rect = [sender bounds];
    [popover showRelativeToRect:rect ofView:sender preferredEdge:NSMaxYEdge];
}

- (void)popoverDidClose:(NSNotification *)notification {
    popover = nil;
}

- (NSWindow *)detachableWindowForPopover:(NSPopover *)popover {
    return popoverWindow;
}

- (BOOL)popoverShouldDetach:(NSPopover *)popover {
    return YES;
}


@end
